package src.com.atguigu02.trycatchfinally;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * ClassName: ExceptionHandleTest
 * Package: src.com.atguigu02.trycatchfinally
 * Description:
 *
 * @Author BuTang
 * @Create 2023/4/26 21:58
 * @Version 1.0
 */
public class ExceptionHandleTest {
    @Test
    public void test1() {
        try {
            Scanner sca = new Scanner(System.in);
            int num = sca.nextInt();
            System.out.println(num);
        } catch (NumberFormatException e) {
            System.out.println("出现了NumberForMatException");
        } catch (InputMismatchException e) {
            System.out.println("出现了InputMismatchException");
        } catch (RuntimeException e) {
            System.out.println("出现了RuntimException");
        }
        System.out.println("异常处理结束，代码继续执行");
    }
    @Test
    public void test2() {
        try {
            File file = new File("E\\hello.text");
            FileInputStream fis = new FileInputStream(file);
            int data = fis.read();
            while (data != -1) {
                System.out.println((char) data);
                data = fis.read();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
